<?php

/**
 * Yii Controller UserController
 *
 * @author anhdung
 * @since 23-05-2013 - 09:52:31
 */
class UserController extends MyController
{

    public function actions()
    {
        return array(
            'captcha' => array(
                'class' => 'CCaptchaAction',
                'backColor' => 0xF7F3F3,
            ),
        );
    }

    public function actionRegister()
    {
        $model = new User;
        if (isset($_POST['ajax']) && $_POST['ajax'] === 'register-form')
        {
            echo CActiveForm::validate($model);
            Yii::app()->end();
        }
        if (isset($_POST['User']))
        {
            $model->setAttributes($_POST['User']);
            if ($model->save())
            {
                $model->type = Contact::STATUS_NEW;
                Yii::app()->user->setFlash('register', yii::t('register', 'You have successfully registered.'));
                $this->refresh();
            }
            else
            {
                Yii::app()->user->setFlash('register', yii::t('register', 'You are not registered successfully please check back'));
            }
        }
        $this->render('register', array('model' => $model));
    }

    public function actionLogin()
    {
        $model = new User();
        if (isset($_POST['ajax']) && $_POST['ajax'] === 'login-form')
        {
            echo CActiveForm::validate($model);
            Yii::app()->end();
        }
        $this->render('login', array('model' => $model));
    }

}

/** 
 * End file UserController
 */
